package Assignment;

import Code.Test.Test1;

/*
需求：定义一个方法copyOf(int[] arr, int newLength)
功能：将数组arr中的newLength个元素拷贝到新数组中，并将新数组返回，从索引为0开始
 */
public class Test9 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6};

        int[] newArr = copyOf(arr,2);

        //遍历数组
        Test1.Traversal(newArr);
    }
    public static int[] copyOf(int[] arr, int newLength){
        int[] newArr = new int[newLength];

        for (int i = 0; i < newLength; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }
}
